import requests
import json
import redis
import time
import datetime
conn = redis.Redis()
checkUrl = 'https://home.jd.com/'
while True:
    res = conn.hkeys("jd_cookie")
    for c in res:
        cookies = conn.hget("jd_cookie", c.decode())
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            "Cookie": cookies.decode()
        }
        rsp = requests.get(checkUrl, headers=headers)
        # print(rsp.content)
        now = datetime.datetime.now()
        if 'login' in str(rsp.url):
            print(now, c.decode(), '登录过期， 请重新登录！')
        else:
            print(now, c.decode(), "登录正常")

    time.sleep(60*10)